Skip to content

Accept grouped short options such as -qfcsv in rfl::cli - #24

Open
clockblocker wants to merge 1 commit into
wave-base-5from
cli-grouped-short-options
Open

clockblocker wants to merge 1 commit into
wave-base-5from
cli-grouped-short-options

Conversation

@clockblocker

@clockblocker clockblocker commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds POSIX-style grouped short options (such as -qv, -fcsv, -qf csv) to rfl::cli::read. Purely additive — no input that parses on main changes meaning.

Example

struct Config {
  rfl::Short<"q", rfl::DefaultVal<bool>> quiet = false;
  rfl::Short<"v", rfl::DefaultVal<bool>> verbose = false;
  rfl::Short<"f", std::optional<std::string>> format;
  rfl::Short<"p", std::optional<int>> priority;
};
Input Result
-qv quiet=true, verbose=true
-fcsv / -qfcsv / -qf csv format="csv" (and quiet=true)
-qv false quiet=true, verbose=false
-p-42 / -p -42 priority=-42 (-42 alone stays positional)
-vq=false Option '-q' does not take a value in '-vq=false'. Write '-q=false' on its own.
-qxf Unknown short argument: -x (in '-qxf').

Key details

  • Flags consume one character each; the first value-taking option takes the rest of the token (or the next token if at the end of the group).
  • Negative numbers remain positional unless a digit short option (e.g. rfl::Short<"1", ...>) is declared.
  • Public table-less parse_argv(argc, argv) is unchanged.
  • Docs updated in cli.md ("Grouped short options").

Open question: -f=csv and -qf=csv parse as "csv" (matching main's -f=csv), whereas getopt gives "=csv". Keep main's behavior or match getopt?

AI-authored. Depends on: #22 (applied on #33, #34).

rfl::cli::read now accepts several short options in one token: in
`-qvf` every flag is set up to the first option that takes a value,
which takes the rest of the token (`-qfcsv`) or, if nothing is left,
the next token (`-qf csv`). `-f=csv` keeps meaning "csv". A flag inside a
group takes no value, and an unknown letter fails with
"Unknown short argument: -x (in '-qxf').".

Inputs that parsed before keep their meaning. Grouping needs the option
table, so the public parse_argv still reads `-abc` as the short option
"abc".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant